﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using Arizu.Repository;
using System.Data;

namespace AiRiZu.User.handler
{
    public class ValidateBook : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Session["logId"] == null)
            {
                context.Response.Write("nologin");
            }
            else
            {
                AirizuUser airizuUser = AirizuUser.CreateInstance();
                DataTable dt = airizuUser.GetUser(long.Parse(context.Session["logId"].ToString()));

                if (dt.Rows.Count > 0)
                {
                    Notification.SendEmail(dt.Rows[0]["Email"].ToString(), "您的房间预定请求已提交，请等待房东确认", "您的预订请求已经成功提交，房东将有24小时来接受或拒绝您的请求。");
                }

                AirizuRoom airizuRoom = AirizuRoom.CreateInstance();

                DataTable dtRoom = airizuRoom.GetRoom(0);
                if (dtRoom.Rows.Count > 0)
                {
                    long ownerId = long.Parse(dtRoom.Rows[0]["OwnerId"].ToString());
                    DataTable dtOwner = airizuUser.GetUser(ownerId);
                    Notification.SendEmail(dtOwner.Rows[0]["Email"].ToString(), "有人预定您的房间，请审核确认", "有人预定您的房间，请审核确认。");
                }

                context.Response.Write("success");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
